<?php

namespace App\Providers;
//引入对应的命名空间
use Illuminate\Support\Facades\Schema;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;
use Laravel\Passport\Passport;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //$this->registerPolicies();
        //token认证有效期2小时
        Passport::tokensExpireIn(now()->addHour(2));
        //刷新token认证有效期30天
        Passport::refreshTokensExpireIn(now()->addDay(30));

        Schema::defaultStringLength(191);
        //自定义验证规则
        Validator::extend('phone', function ($attribute, $value, $parameters, $validator) {
            // 返回true或false
            $reg1 = '/^\+86-1[3-9]\d{9}$/';
            $reg2 = '/^1[3-9]\d{9}$/';
            return preg_match($reg1,$value)||preg_match($reg2,$value);
        });


    }
}
